home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.7 / tcpdump- / tcpdump-richard-1.7 / tcpdump-3.0 / print-llc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-03  |  5.1 KB  |  198 lines

  1. /*
  2.  * Copyright (c) 1992, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. /*
  23.  * Code by Matt Thomas, Digital Equipment Corporation
  24.  *    with an awful lot of hacking by Jeffrey Mogul, DECWRL
  25.  */
  26.  
  27. #ifndef lint
  28. static  char rcsid[] =
  29.     "@(#)$Header: print-llc.c,v 1.13 94/06/14 20:18:45 leres Exp $";
  30. #endif
  31.  
  32. #include <sys/param.h>
  33. #include <sys/time.h>
  34. #include <sys/types.h>
  35.  
  36. #include <netinet/in.h>
  37.  
  38. #include <ctype.h>
  39. #include <string.h>
  40. #include <errno.h>
  41. #include <netdb.h>
  42. #include <signal.h>
  43. #include <stdio.h>
  44.  
  45. #include "interface.h"
  46. #include "addrtoname.h"
  47. #include "extract.h"            /* must come after interface.h */
  48.  
  49. #include "llc.h"
  50.  
  51. static struct token cmd2str[] = {
  52.     { LLC_UI,    "ui" },
  53.     { LLC_TEST,    "test" },
  54.     { LLC_XID,    "xid" },
  55.     { LLC_UA,    "ua" },
  56.     { LLC_DISC,    "disc" },
  57.     { LLC_DM,    "dm" },
  58.     { LLC_SABME,    "sabme" },
  59.     { LLC_FRMR,    "frmr" },
  60.     { 0,        NULL }
  61. };
  62.  
  63. /*
  64.  * Returns non-zero IFF it succeeds in printing the header
  65.  */
  66. int
  67. llc_print(const u_char *p, int length, int caplen,
  68.       const u_char *esrc, const u_char *edst)
  69. {
  70.     struct llc llc;
  71.     register u_short et;
  72.     register int ret;
  73.  
  74.     if (caplen < 3) {
  75.         (void)printf("[|llc]");
  76.         default_print((u_char *)p, caplen);
  77.         return(0);
  78.     }
  79.  
  80.     /* Watch out for possible alignment problems */
  81.     bcopy((char *)p, (char *)&llc, min(caplen, sizeof(llc)));
  82.  
  83.     if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) {
  84.         ipx_print(p, length);
  85.         return (1);
  86.     }
  87. #ifdef notyet
  88.     else if (p[0] == 0xf0 && p[1] == 0xf0)
  89.         netbios_print(p, length);
  90. #endif
  91.     if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS
  92.         && llc.llcui == LLC_UI) {
  93.         isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst);
  94.         return (1);
  95.     }
  96.  
  97.     if (llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP
  98.         && llc.llcui == LLC_UI) {
  99.         if (caplen < sizeof(llc)) {
  100.             (void)printf("[|llc-snap]");
  101.             default_print((u_char *)p, caplen);
  102.             return (0);
  103.         }
  104.         if (vflag)
  105.             (void)printf("snap %s ", protoid_string(llc.llcpi));
  106.  
  107.         caplen -= sizeof(llc);
  108.         length -= sizeof(llc);
  109.         p += sizeof(llc);
  110.  
  111.         /* This is an encapsulated Ethernet packet */
  112.         et = EXTRACT_SHORT(&llc.ethertype[0]);
  113.         ret = ether_encap_print(et, p, length, caplen);
  114.         if (ret)
  115.             return (ret);
  116.     }
  117.  
  118.     if ((llc.ssap & ~LLC_GSAP) == llc.dsap) {
  119.         if (eflag)
  120.             (void)printf("%s ", llcsap_string(llc.dsap));
  121.         else
  122.             (void)printf("%s > %s %s ",
  123.                     etheraddr_string(esrc),
  124.                     etheraddr_string(edst),
  125.                     llcsap_string(llc.dsap));
  126.     } else {
  127.         if (eflag)
  128.             (void)printf("%s > %s ",
  129.                 llcsap_string(llc.ssap & ~LLC_GSAP),
  130.                 llcsap_string(llc.dsap));
  131.         else
  132.             (void)printf("%s %s > %s %s ",
  133.                 etheraddr_string(esrc),
  134.                 llcsap_string(llc.ssap & ~LLC_GSAP),
  135.                 etheraddr_string(edst),
  136.                 llcsap_string(llc.dsap));
  137.     }
  138.  
  139.     if ((llc.llcu & LLC_U_FMT) == LLC_U_FMT) {
  140.         const char *m;
  141.         char f;
  142.         m = tok2str(cmd2str, "%02x", LLC_U_CMD(llc.llcu));
  143.         switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
  144.             case 0:            f = 'C'; break;
  145.             case LLC_GSAP:        f = 'R'; break;
  146.             case LLC_U_POLL:        f = 'P'; break;
  147.             case LLC_GSAP|LLC_U_POLL:    f = 'F'; break;
  148.             default:            f = '?'; break;
  149.         }
  150.  
  151.         printf("%s/%c", m, f);
  152.  
  153.         p += 3;
  154.         length -= 3;
  155.         caplen -= 3;
  156.  
  157.         if ((llc.llcu & ~LLC_U_POLL) == LLC_XID) {
  158.             if (*p == LLC_XID_FI) {
  159.             printf(": %02x %02x", p[1], p[2]);
  160.             p += 3;
  161.             length -= 3;
  162.             caplen -= 3;
  163.             }
  164.         }
  165.     } else {
  166.         char f;
  167.         llc.llcis = ntohs(llc.llcis);
  168.         switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
  169.             case 0:            f = 'C'; break;
  170.             case LLC_GSAP:        f = 'R'; break;
  171.             case LLC_U_POLL:        f = 'P'; break;
  172.             case LLC_GSAP|LLC_U_POLL:    f = 'F'; break;
  173.             default:            f = '?'; break;
  174.         }
  175.  
  176.         if ((llc.llcu & LLC_S_FMT) == LLC_S_FMT) {
  177.             static char *llc_s[] = { "rr", "rej", "rnr", "03" };
  178.             (void)printf("%s (r=%d,%c)",
  179.                 llc_s[LLC_S_CMD(llc.llcis)],
  180.                 LLC_IS_NR(llc.llcis),
  181.                 f);
  182.         } else {
  183.             (void)printf("I (s=%d,r=%d,%c)",
  184.                 LLC_I_NS(llc.llcis),
  185.                 LLC_IS_NR(llc.llcis),
  186.                 f);
  187.         }
  188.         p += 4;
  189.         length -= 4;
  190.         caplen -= 4;
  191.     }
  192.     (void)printf(" len=%d", length);
  193.     if (caplen > 0) {
  194.         default_print_unaligned(p, caplen);
  195.     }
  196.     return(1);
  197. }
  198.